package com.kedacom.ldap.demo;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PersonDaoImplTest {
	
	private static PersonDao personDao;

	@Before
	public void setUp() throws Exception {
		ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
		personDao = (PersonDao)cxt.getBean("personDao");
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testCreate() {
		Person person = new Person();
		person.setName("test");
		person.setMail("test@kedacom.com");
		personDao.create(person);
	}

	@Test
	public void testUpdate() {
		Person person = new Person();
		person.setName("test");
		person.setMail("test_modified@kedacom.com");
		personDao.update(person);
	}

	@Test
	public void testDelete() {
		Person person = new Person();
		person.setName("test");
		personDao.delete(person);
	}

	@Test
	public void testFindByPrimaryKey() {
		fail("Not yet implemented");
	}

	@Test
	public void testFindByName() {
		List<Person> list = personDao.findByName("何霄刚");
		if(!list.isEmpty()){
			System.out.println(list.get(0).getMail());
		}else{
			System.out.println("没有找到");
		}
	}

	@Test
	public void testFindAll() {
		List<Person> list = personDao.findAll();
		if(!list.isEmpty()){
			for(Person person : list){
				System.out.println("姓名："+person.getName()+"	邮箱："+person.getMail());
			}
		}else{
			System.out.println("没有找到");
		}
	}

}
